define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'serviceorder/index' + location.search,
                    add_url: 'serviceorder/add',
                    edit_url: 'serviceorder/edit',
                    del_url: 'serviceorder/del',
                    multi_url: 'serviceorder/multi',
                    import_url: 'serviceorder/import',
                    table: 'service_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'expert_user_id', title: __('Expert_user_id')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'fare_price', title: __('Fare_price'), operate:'BETWEEN'},
                        {field: 'real_price', title: __('Real_price'), operate:'BETWEEN'},
                        {field: 'refund_price', title: __('Refund_price'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6')}, formatter: Table.api.formatter.status},
                        {field: 'service_date', title: __('Service_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'service_time', title: __('Service_time')},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'audit_time', title: __('Audit_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'reach_address', title: __('Reach_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'reach_lng', title: __('Reach_lng'), operate: 'LIKE'},
                        {field: 'reach_lat', title: __('Reach_lat'), operate: 'LIKE'},
                        {field: 'reach_image', title: __('Reach_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'reach_time', title: __('Reach_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'start_address', title: __('Start_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_lng', title: __('Start_lng'), operate: 'LIKE'},
                        {field: 'start_lat', title: __('Start_lat'), operate: 'LIKE'},
                        {field: 'start_image', title: __('Start_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'complete_address', title: __('Complete_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'complete_lng', title: __('Complete_lng'), operate: 'LIKE'},
                        {field: 'complete_lat', title: __('Complete_lat'), operate: 'LIKE'},
                        {field: 'complete_image', title: __('Complete_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'complete_time', title: __('Complete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'deteletime', title: __('Deteletime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
